#include <iostream>
# include <windows.h>
#include <tuple>

using namespace std;

tuple<int, int, int> IntEq() {
    // 初始化一个100万成员的int类型数组，全部存储偶数，最后一个数组存储：
    const int num = 2000000;
    const int coefficient = 1000; // 设置一个值系数，将存储数组的值放大1000倍，便于测试程序性能

    int *arrEvent = new int[num / 2 + 1]; // 存储偶数100万 + 1个相等元素
    int *arrOdd = new int[num / 2 + 1]; // 存储偶数100万 + 1个相等元素

    int eventIndex = 0, oddIndex = 0;

    for (int i = 1; i <= num; i++) {
        if (i % 2 == 0) {
            arrEvent[eventIndex] = i * coefficient;
            eventIndex++;
        } else {
            arrOdd[oddIndex] = i * coefficient;
            oddIndex++;
        }
    }

    // 最后一个数字相同
    arrEvent[eventIndex] = coefficient * (num + 1);
    arrOdd[oddIndex] = coefficient * (num + 1);

    // 开始比较
    int neqCounts = 0, eqCounts = 0, eqVal = 0;

    for (int i = 0; i <= num / 2; ++i) {
        if (arrEvent[i] == arrOdd[i]) {
            eqCounts++;
            eqVal = arrOdd[i];
        } else {
            neqCounts++;
        }
    }

    return make_tuple(neqCounts, eqCounts, eqVal);
}

int main() {
    DWORD startSec = GetTickCount();
    int neqCounts = 0, eqCounts = 0, eqVal = 0;
    for (int i = 0; i < 10; i++) {
        tie(neqCounts, eqCounts, eqVal) = IntEq();
    }
    cout << "两个100万成员的数组中，不相等的个数：" << neqCounts << " 相等的个数：" << eqCounts << " 相等值：" << eqVal << " 单次耗时(ms): " << (GetTickCount() - startSec) / 10 << endl;

    return 0;
}
